#include <errno.h>
#include <sys/timerfd.h>
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/select.h>
#include <fcntl.h>
#include <stdint.h>
#include <sys/sysinfo.h>

int delayms(int ms)
{
    int ret;
    struct timeval timeout;
    timeout.tv_sec = ms / 1000;
    timeout.tv_usec = (ms % 1000) * 1000;
    do
    {
        ret = select(0, NULL, NULL, NULL, &timeout);
        if (ret < 0 && errno == EINTR)
        {
            //printf("signal break,continue\n");
            continue;
        }
        else if (ret < 0)
        {
            return -1;
        }
    } while (ret != 0);
    return 0;
}